<template>
	<view class="contain" :style="{ paddingTop: setmargintop() + 'px' }">
		<view class="new-top-nav">
			<uni-nav-bar title="已咨询产品" backgroundColor="#fff" color="#000" statusBar="true"
				@clickLeft="back()" left-icon="arrowleft"></uni-nav-bar>
		</view>
		<view class="contain-view">
			<view class="searchs">
				<!-- search模块 -->
				<view class="search">
					<view class="testop">
						<view class="buttime">
							<view class="center">
								<image src="@/static/socialized-service/breed/guanjian.png" mode="aspectFit"></image>
								<uni-easyinput class="uni-mt-5" v-model="searchName" :inputBorder="false" placeholder="关键词"></uni-easyinput>
							</view>
						</view>
					</view>
				</view>
				<view class="btn" @click="goSearch">搜索</view>
			</view>
			
			<scroll-view scroll-y="true" :style="{height:setcollapseheight() + 'px'}" :scroll-top="scrollTop" @scroll="onScroll"
				@scrolltolower="handleScrolltolowerone()">
				<view v-if="dataList.length != 0" class="pro-box">
					<view class="pro-card" v-for="item,index in dataList" :key="index">
						<view class="left-page" v-if="item.product.imgList.length>0">
							<image class="pro-img" :src="item.product.imgList[0] && item.product.imgList[0].productImgUrl" mode="scaleToFill"></image>
						</view>
						<view class="right-page">
							<view class="title">{{ item.product.productTitle }}</view>
							<view class="content">{{ item.product.productContent }}</view>
							<view class="btn">
								<button @click="toProDetail(item)" class="btn-view">查看详情</button>
							</view>
							<!-- <image class="view-item-img" src="@/static/socialized-service/financial-insurance/jing.png" mode="heightFix"></image> -->
						</view>
					</view>
				</view>
			
				<view v-if="dataList.length == 0" class="facility-view-nodata">
					<image class="facility-view-blankimg" mode="widthFix" src="@/static/blank.png"></image>
					<view class="facility-view-nodata-line">
						暂无数据
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import productApi from '@/api/socialized-servce/financial-insurance/product/index.js'
	export default {
		data() {
			return {
				selected: 0,
				scrollTop: 0,
				oldScrollTop: 0,
				// 可选择跳转页面数据
				selectViewList: [
					{
						name: "全部",
						value: "",
					},
					{
						name: "金融产品",
						value: 0,
					},
					{
						name: "保险产品",
						value: 1,
					},
				],
				searchName: '',
				dataList: [],
				techPage: {
					page: 1,
					size: 10,
					total: 0,
				},
			}
		},
		onPullDownRefresh() {
			this.searchName = ''
			this.searchParam = {}
			this.updataContent()
			setTimeout(function() {
				uni.stopPullDownRefresh()
			}, 1000)
		},
		onLoad(e) {
			this.userId = e.userId
		},
		onShow() {
			this.loadDataList()
		},
		methods: {
			selectViewFn(i) {
				this.searchName = ''
				this.searchParam = {}
			
				this.selected = i
				this.financialAndInsuranceFlag = row.value
				this.techPage.page = 1
				this.loadDataList()
			},
			onScroll(e) {
				this.oldScrollTop = e.detail.scrollTop
			},
			// 获取产品列表
			loadDataList () {
				productApi.queryPageByConditionUser({
					...this.techPage,
					condition: {
						product: {
							...this.searchParam,
						},
						userId: this.userId
					}
				}).then(res => {
					let list = res.data.content
					this.techPage.total = res.data.totalElements
					if (this.techPage.page == 1) {
						this.dataList = list
						this.scrollTop = this.oldScrollTop
						this.$nextTick(() =>{
							this.scrollTop = 0
						})
					} else {
						this.dataList.push(...list)
					}
				})
			},
			// 搜索
			goSearch() {
				this.searchParam = {
					productTitle: this.searchName,
				}
				this.updataContent()
			},
			updataContent() {
				this.techPage.page = 1
				this.loadDataList()
			},
			// 跳转到详情
			toProDetail(row) {
				const url = '/subPage1/socialized-service/financial-insurance/product/product-detail/index'
				this.$togo(url, { productId: row.productId, productUserId: row.productUserId, adviced: true })
			},
			// 上拉加载更多
			handleScrolltolowerone() {
				let len = this.techPage.page * this.techPage.size
				if (len >= this.techPage.total) return
				this.techPage.page += 1
				this.loadDataList()
			},
			// 设置顶部高度
			setmargintop() {
				let top = 0
				top = this.customBar + 10
				return top
			},
			//  设置内容高度
			setcollapseheight() {
				let topheightone = uni.upx2px(180)
				let newheight = this.customBar + topheightone
				let winHeight = 0
				uni.getSystemInfo({
				  success: function(res) {
					winHeight = res.windowHeight
				  }
				});
				winHeight = parseInt(winHeight) - newheight
				// #ifndef H5
				winHeight = winHeight - 10
				// #endif
				return winHeight
			},
			//返回上一步
			back() {
				uni.navigateBack({ delta: 1 })
			}
		}
	}
</script>

<style lang="scss" scoped>
	.contain {
		width: 100%;
		font-size: 14px;
		line-height: 24px;

		.new-top-nav {
			width: 100%;
			position: fixed;
			top: 0;
			z-index: 99;
		}

		.contain-view {
			margin: 0 30rpx;
			position: relative;
			
			.searchs {
				position: relative;
				display: flex;
				padding-top: 16rpx;
				align-items: center;
				justify-content: center;
				margin-bottom: 20rpx;
				
				.search {
					width: calc(100% - 120rpx);
					height: 80rpx;
					border-radius: 60rpx;
					background-color: rgba(255, 255, 255, 1);
					border: 1px solid rgba(0, 0, 0, 0.05);
					box-shadow: 0px 0px 6px rgba(0, 0, 0, 0.05);
					display: flex;
					justify-content: center;
					align-items: center;
					overflow: hidden;
				
					.testop {
						flex: 35%;
						color: #FFFFFF;
						height: 50rpx;
						border-right: 4rpx #cccbce solid;
						margin-left: 5rpx;
						padding-right: 10rpx;
						font-size: 30rpx;
						
						&:last-child {
							border-right: none;
						}
				
						.buttime {
							color: #959497;
							height: 50rpx;
							white-space: nowrap;
							font-weight: 600;
							display: flex;
							justify-content: space-between;
							align-items: center;
						}
				
						.center {
							display: flex;
							justify-content: center;
							align-items: center;
							width: 100%;
				
							.textt {
								width: 190rpx;
								overflow: hidden;
								text-overflow: ellipsis;
								white-space: nowrap;
							}
				
							image {
								width: 50rpx;
								height: 50rpx;
								margin-right: 10rpx;
								margin-left: 10rpx;
							}
						}
					}
				}
				
				.btn {
					position: relative;
					z-index: 66;
					width: 120rpx;
					height: 64rpx;
					margin-left: 8rpx;
					font-size: 28rpx;
					line-height: 64rpx;
					text-align: center;
					color: #FFFFFF;
					background: linear-gradient(18deg, #43A2FF 0%, #62B1FF 100%);
					border-radius: 40rpx 40rpx 40rpx 40rpx;
					opacity: 1;
				}
			}
			
			.pro-box {
				overflow: auto;
				
				.pro-card {
					background-color: #fff;
					border-radius: 12rpx;
					padding: 40rpx 30rpx 30rpx;
					position: relative;
					border-top: 4rpx solid #8dc5ff;
					display: flex;
					margin-bottom: 30rpx;
					
					.left-page {
						width: 170rpx;
						height: 170rpx;
						margin-right: 20rpx;
						.pro-img {
							width: 100%;
							height: 100%;
						}
					}
					
					.right-page {
						width: calc(100% - 175rpx);
						.title {
							font-size: 40rpx;
							margin-bottom: 10rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}
						.content {
							height: 40rpx;
							margin-bottom: 12rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}
						.btn {
							.btn-view {
								width: 180rpx;
								font-size: 24rpx;
								float: right;
								color: #047ffc;
								background-color: #fff;
								border: 2rpx solid #047ffc;
								border-radius: 40rpx;
							}
						}
						.view-item-img {
							position: absolute;
							width: 50rpx;
							height: 50rpx;
							right: 50rpx;
							top: -4rpx;
						}
					}
				}
			}
		}
	}
	
</style>
